<!DOCTYPE html>
<html lang="en">
<include file="CommonSidebar:common-head"/>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/css/common.css">
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-md-12">
                <h1 class="page-header">所有用户信息</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                    <div class="panel panel-default">
                        <div class="panel-heading" role="tab" id="headingOne">
                            <h4 class="panel-title">
                                <a role="button" data-toggle="collapse" data-parent="#accordion"
                                   href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                    搜索栏
                                </a>
                            </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel"
                             aria-labelledby="headingOne">
                            <div class="panel-body">
                                <form action="{:U('Index')}" class="form-horizontal" method="get">

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">用户微信昵称</label>

                                        <div class="col-sm-4">
                                            <input class="form-control" name="user_wx_name" id="user_wx_name"
                                                   value="{$CSDATA.user_wx_name}">
                                        </div>
                                        <label class="col-sm-2 control-label">性别</label>

                                        <div class="col-sm-4">
                                            <select class="form-control" name="user_gender" id="user_gender">
                                                <option value="">All</option>
                                                <option value="1">男</option>
                                                <option value="2">女</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">微信标签</label>

                                        <div class="col-sm-4">
                                            <foreach name="WX_LABLE" item="v">
                                                <input onclick="SelectWXLABLE($(this))" type="checkbox"
                                                       name="lable_id[]"
                                                       value="{$v.region_code}">{$v.region_name}
                                            </foreach>

                                        </div>
                                        <label class="col-sm-2 control-label">城市</label>

                                        <div class="col-sm-4">
                                            <select name="user_area_shi" class="form-control ">
                                                <option value="{$CSDATA.user_area_shi}">{$CSDATA.user_area_shi}</option>
                                                <foreach name="CITY" item="v">
                                                    <option value="{$v.user_area_shi}">{$v.user_area_shi}</option>
                                                </foreach>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">注册开始时间</label>

                                        <div class="col-sm-4">
                                            <div class='input-group date'>
                                                <input name="time1" type='text' class="form-control datetimepicker_mask"
                                                       id="time1" value="{$CSDATA.time1}"/>
                                                <span class="input-group-addon">
                                                    <span class="glyphicon glyphicon-calendar"></span>
                                                </span>
                                            </div>
                                        </div>
                                        <label class="col-sm-2 control-label">注册结束时间</label>

                                        <div class="col-sm-4">
                                            <div class='input-group date'>
                                                <input name="time2" id="time2" type='text'
                                                       class="form-control datetimepicker_mask"
                                                       value="{$CSDATA.time2}"/>
                                                <span class="input-group-addon">
                                                    <span class="glyphicon glyphicon-calendar"></span>
                                                </span>
                                            </div>
                                        </div>
                                    </div>

                                    <input class="form-control" type="hidden" name="user_id" value="{$CSDATA.user_id}">

                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <button type="submit" class="btn  btn-primary">筛选</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="row">
                        <div class="col-lg-3">
                            <button onclick='SendAllUser()' class="btn  btn-primary">发送消息给筛选出来的用户，共{$count}个用户</button>
                        </div>
                        <div class="col-lg-2">
                            <button onclick='AddYhCard()' class="btn  btn-primary">添加优惠劵</button>
                        </div>
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <include file="Extends/searchForUser"/>
                                <thead>
                                <tr style="color: #008200;color-interpolation: red;align-content: center">
                                    <th style="text-align:center"><input name="all_checkbox" type='checkbox'
                                                                         id="all_checkbox"></th>
                                    <th class="text-center GridSortTh" width="15%" data-order="USER_ID">
                                        USER_ID(微信OPENID)
                                    </th>
                                    <th class="text-center GridSortTh" data-order="user_wx_name">微信昵称</th>
                                    <th class="text-center GridSortTh" width="85px" data-order="user_image">头像</th>
                                    <th class="text-center GridSortTh" data-order="user_gender">性别</th>
                                    <th width="80px">账号余额</th>
                                    <th class="text-center GridSortTh" data-order="user_hs_book_money">赚了多少钱</th>
                                    <th class="text-center GridSortTh" data-order="user_area_sheng"
                                        style="text-align:center" width="80px">省
                                    </th>
                                    <th class="text-center GridSortTh" data-order="user_area_shi"
                                        style="text-align:center" width="80px">市
                                    </th>
                                    <th class="text-center GridSortTh" data-order="user_time">注册时间</th>
                                    <th class="text-center GridSortTh" data-order="login_time">最近登录时间</th>
                                    <th style="text-align:center">孩子信息</th>
                                    <th style="text-align:center" width="10%">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <foreach name="data" item="v">
                                    <tr>
                                        <td><input type='checkbox' name='checkbox' value="{$v.user_id}"></td>
                                        <td>{$v.user_id}<br/>{$v.user_wx}</td>
                                        <td>{$v.user_wx_name}</td>
                                        <td><img src="{$v.user_image}" width="80px"></td>
                                        <td>
                                            <if condition="$v.user_gender == 1">
                                                男
                                            </if>
                                            <if condition="$v.user_gender == 2">
                                                女
                                            </if>
                                            <if condition="$v.user_gender == 0">
                                                未知
                                            </if>
                                        </td>
                                        <td><a onclick="LookUserMoney('{$v.user_id}')">查看</a></td>
                                        <td>{$v.user_hs_book_money}</td>
                                        <td>{$v.user_area_sheng}</td>
                                        <td>{$v.user_area_shi}</td>
                                        <td>{$v.user_time}</td>
                                        <td>{$v.login_time}</td>
                                        <td><a href="{:U('Children/Index')}?ID={$v.user_id}" target='_blank'
                                               class='btn  btn-primary'>查看</a>
                                        </td>
                                        <td>
                                            <a class="btn btn-warning btn-xs"
                                               href="{:U('Order/Index')}?order_type=0&user_id={$v.user_id}">查看ta的买书订单</a>
                                            <a class="btn btn-danger btn-xs"
                                               href="{:U('GetOrder/Index')}?order_type=0&user_id={$v.user_id}">查看ta的卖书订单</a>
                                        </td>

                                    </tr>
                                </foreach>
                                </tbody>
                            </table>
                            <div class="blue">{$show}</div>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->
</div>

<!--查看余额-->
<div id="LookUserMoney" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">查看余额</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <input id="order_id" type="hidden" name="order_id" value="">

                        <div class="col-xs-12">
                            <label>用户余额</label>
                            <span id="userCost" style="color: red"></span>
                        </div>
                    </div>
                    <if condition="outS('USER_NAME') == 'mao'">
                        <form action="{:U('Cost/UpdateCost')}" method="post">
                            <input id="USER_ID" name="USER_ID" value="" hidden>

                            <div class="row">
                                <div class="col-xs-12">
                                    <label>超级管理员加减余额</label>
                                    <input name="updateCost" value="">
                                </div>
                            </div>
                            <button type="submit">修改</button>
                        </form>
                    </if>
                </div>
            </div>
        </div>
    </div>
</div>
<!--查看余额-->

<!--信息模板-->
<div id="Sendmodle" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">消息体</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-xs-12">
                            <label>Title信息:</label>
                            <input id="TITLE" name="TITLE" class="rugby-login form-control"
                                   value="团购 | 你能用一顿KFC的钱买来孩子的幽默感，这就是幸福。">
                        </div>
                        <div class="col-xs-12">
                            <label>书籍名称/主题:</label>
                            <input id="BOOK_NAME" name="BOOK_NAME" class="rugby-login form-control"
                                   value="《小猪小象》双语版 团购价69 下单减免更划算">
                        </div>
                        <div class="col-xs-12">
                            <label>消息详情链接:</label>
                            <input id="URL" name="URL" class="rugby-login form-control"
                                   value="https://h5.youzan.com/v2/goods/36bitpa8zshd7">
                        </div>
                        <div class="col-xs-12">
                            <label>开团时间:</label>
                            <input id="TIME" name="TIME" class="rugby-login form-control" value="2017-12-19">
                        </div>
                        <div class="col-xs-12">
                            <label>地址:</label>
                            <input id="Address" name="Address" class="rugby-login form-control" value="奇妙阅">
                        </div>
                        <div class="col-xs-12">
                            <label>底部信息:</label>
                            <input id="DB_DATA" name="DB_DATA" class="rugby-login form-control" value="点击查看详情>>">
                        </div>
                        <div class="col-xs-12">
                            <s onclick="sendAll()"
                               class="btn btn-block btn-primary">发送给所有用户
                            </s>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--信息模板-->

<!--进度条-->
<div class="modal fade dialogsecc" id="myModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="height:30px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel"></h4>
            </div>
            <div class="modal-body">
                <div class="progress" style="    background: #CCC;    margin: 0;    height: 50px;    border-radius: 0;">
                    <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0"
                         aria-valuemax="100" style="width: 60%; ">
                        60%
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="height:30px;">

            </div>
        </div>
    </div>
</div>
<!--进度条-->

<!--添加优惠劵-->
<div id="AddCard" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">添加优惠劵</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <input type="hidden" name="USER_IDS" id="USER_IDS">

                    <div class="row">
                        <div class="col-xs-12">
                            <label>派送用户数:</label>
                            <span style="color: red" id="USER_NUM"></span>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-12">
                            <label>优惠劵</label>
                            <select class="rugby-login form-control" name="CARD_ID" id="CARD_ID">
                                <foreach name="COUPON_DATA" item="v" key="k">
                                    <option value="{$v.ID}">{$v.NAME}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button onclick="SendYHJCard()">
                    确认
                </button>
            </div>
        </div>
    </div>
</div>
<!--添加优惠劵-->

<include file="CommonSidebar:common-script"/>
<script src="__PUBLIC__/Admin/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="__PUBLIC__/Admin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
<script src="__PUBLIC__/Common/grid.js"></script>
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>


<script type="text/javascript">
    $('#dataTables-example').grid({
        singleSelect: false
    });

    //
    <!--全选择框-->
    $("#all_checkbox").click(function () {
        if ($(this).is(':checked')) {
            $("input[name='checkbox']").each(function () { //循环checkbox选择或取消
                console.log($(this));
                $(this).prop("checked", "true");
            });
        } else {
            $("input[name='checkbox']").removeAttr("checked", false);

        }
    });
    //    获取选择框
    function Getcheckbox() {
        var vals = [];
        $("input[name='checkbox']:checkbox:checked").each(function (index, item) {
            vals.push($(this).val());
            $(this).hide();
        });
        if (vals.length <= 0) {
            return 0;
        }
        return vals;
    }
    //添加用户劵弹窗
    function AddYhCard() {
        var check = Getcheckbox();
        if (check == 0) {
            alert('请选择用户');
        } else {
            $('#USER_NUM').html(check.length);
            $('#USER_IDS').html(check);
            $('#AddCard').modal('show');
        }
    }
    //发送优惠劵
    function SendYHJCard(){
        var check = Getcheckbox();
        if (confirm("是否确认发送给"+check.length+"个人？？")) {
            YHJ_ajaxing(check.length);
        }
    }
    function YHJ_ajaxing(counts) {
        alert("总共发送:" + counts + "条");
        YHJ_ajaxing2(0, counts);
    }
    function YHJ_ajaxing2(id, counts) {
        var check = Getcheckbox();
        var USER_ID = check[id];
        var CARD_ID = $('#CARD_ID').val();
        var jdd = ((id / counts) * 100);
        console.log(USER_ID);
        $(".progress-bar").html(jdd.toFixed(1) + '%').width(jdd + '%');
        if (id < counts) {
            $("#myModal").modal();
            $.post("{:U('Coupon/AddCouponLog')}",
                    {
                        USER_ID: USER_ID,
                        CARD_ID: CARD_ID,
                        TYPE: 1
                    },
                    function (data) {
                        if (data) {
                            setTimeout(YHJ_ajaxing2((id + 1), counts), 300);
                        } else {
                            alert("发送失败哦");
                        }
                    });
        } else {
            location.reload();
            return false;
        }
    }

</script>
<script>
    //限制微信标签
    function SelectWXLABLE(elem) {
        var user_wx_lable = elem.val();
//        window.location.href = "{:U('User/Index')}?user_wx_lable="+user_wx_lable;

    }


    //发送所有人
    function SendAllUser() {
        var user_wx_name = $('#user_wx_name').val();
        var user_gender = $('#user_gender').val();
        var time1 = $('#time1').val();
        var time2 = $('#time2').val();
        if (confirm("筛选条件\r\n用户微信昵称：" + user_wx_name
                        + "\r\n注册开始时间:" + time1
                        + "\r\n注册结束时间:" + time2
                        + "\r\筛选用户数:{$count}"
                )) {
            $('#Sendmodle').modal('show');
        } else {

        }
    }


    //查看用户余额
    function LookUserMoney(user_id) {
        $.post("{:U('Cost/LookUserMoney')}",
                {USER_ID: user_id},
                function (data) {
                    console.log(data);
                    if (parseInt(data) >= 0) {
                        $('#userCost').html(data);
                        $('#USER_ID').val(user_id);
                        $('#LookUserMoney').modal('show');
                    } else {
                        alert('查看失败,管理员权限不足');
                    }
                });
    }


    //开始发送所有人
    function sendAll() {
        if (confirm("是否确认发送给{$count}个人？？")) {
            var count = {$count};
            ajaxing(count);
        }
    }
    function ajaxing(counts) {
        alert("总共发送:" + counts + "条");
        ajaxing2(0, counts);
    }
    function ajaxing2(id, counts) {
        var jdd = ((id / counts) * 100);
        var TITLE = $("#TITLE").val();
        var BOOK_NAME = $("#BOOK_NAME").val();
        var TIME = $("#TIME").val();
        var Address = $("#Address").val();
        var DB_DATA = $("#DB_DATA").val();
        var URL = $("#URL").val();
        var OPENIDS = {$SendData};
        var OPENID = OPENIDS[id]['user_wx'];

        $(".progress-bar").html(jdd.toFixed(1) + '%').width(jdd + '%');
        if (id < counts) {
            $("#myModal").modal();
            $.post("{:U('WxSendMsg/KT_ALL_SendMsg')}",
                    {
                        OPENID: OPENID,
                        TITLE: TITLE,
                        BOOK_NAME: BOOK_NAME,
                        TIME: TIME,
                        Address: Address,
                        DB_DATA: DB_DATA,
                        URL: URL
                    },
                    function (data) {
                        if (data) {
                            setTimeout(ajaxing2((id + 1), counts), 300);
                        } else {
                            alert("发送失败哦");
                        }
                    });
        } else {
            location.reload();
            return false;
        }
    }

</script>
</body>
</html>
